Raport składa się z kilku rozdziałów. Główne rozdziały są oznaczone
#. Im więcej dodamy # tym bardziej
zagnieżdzony będzie nasz podrozdział.
Komentarze standardowo są poprzez zaznaczenie kodu i użycie kombinacji klawiszy Ctrl + Shift + C.
Na przykład:
Formatowanie tekstu:
Opcje załączania grafik/tabel:
Można również generować kod R w tekście używając 2023-04-20 12:20:42.
toctoc_floattoc_depthcode_foldtheme - https://bootswatch.com/3/df <- iris
colnames(iris)
## [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width" "Species"
head(iris)
## Sepal.Length Sepal.Width Petal.Length Petal.Width Species
## 1 5.1 3.5 1.4 0.2 setosa
## 2 4.9 3.0 1.4 0.2 setosa
## 3 4.7 3.2 1.3 0.2 setosa
## 4 4.6 3.1 1.5 0.2 setosa
## 5 5.0 3.6 1.4 0.2 setosa
## 6 5.4 3.9 1.7 0.4 setosa
head(iris ) %>%
knitr::kable( caption = 'Liczność poszczególnych klas')
| Sepal.Length | Sepal.Width | Petal.Length | Petal.Width | Species |
|---|---|---|---|---|
| 5.1 | 3.5 | 1.4 | 0.2 | setosa |
| 4.9 | 3.0 | 1.4 | 0.2 | setosa |
| 4.7 | 3.2 | 1.3 | 0.2 | setosa |
| 4.6 | 3.1 | 1.5 | 0.2 | setosa |
| 5.0 | 3.6 | 1.4 | 0.2 | setosa |
| 5.4 | 3.9 | 1.7 | 0.4 | setosa |
ggplot(iris)+
geom_point(aes(x = Sepal.Length, y = Sepal.Width))+
theme_bw()
ggplot(iris)+
geom_point(aes(x = Sepal.Length, y = Sepal.Width))+
theme_bw()
Przykładowy wykres
YAML: zmiana html_document ->
bookdown::html_document2:
@ref(fig:plot2)
Dla zmiennych ciągłych utwórz histogram w ggplot2.
numeric_col <- colnames(iris)[sapply(iris,class) == 'numeric']
for (var in numeric_col){
p <- ggplot(iris)+
geom_histogram(aes_string(x = var))+
labs(title = var)
print(p)
}
## Warning: `aes_string()` was deprecated in ggplot2 3.0.0.
## ℹ Please use tidy evaluation ideoms with `aes()`
?DT::datatable
## uruchamianie serwera httpd dla pomocy ... wykonano
iris %>%
group_by(Species) %>%
summarise(cnt = n()) %>%
DT::datatable()
iris %>%
group_by(Species) %>%
summarise(cnt = n()) %>%
DT::datatable(width=10, options = list(dom = 't'))
Więcej o opcjach formatowania tabeli z pakietu DT można
znaleźć https://rstudio.github.io/DT/options.html
library(plotly)
fig <- plot_ly(data = iris, x = ~Sepal.Length, y = ~Petal.Length, color = ~Species, colors = "Set1")
fig